<?php

namespace Act\Logic\Channel;

use Act\Logic\Channel\baseChannel;
use Act\Logic\Channel\Channelinterface;
use common\Factory\Factory;

class QianluChannel extends baseChannel implements Channelinterface {
    
    public function act($data, $aid, $channel) {
        $checkIpResult = $this->checkIp('qianlu');
        if($checkIpResult === false) return array('success' => false, 'message' => 'ip check failed');
        
        $newData = array();
        $newData['IDFA'] = $data['idfa'];
        $newData['EVENTTIME'] = $data['time'];
        $newData['APPSTOREID'] = $data['appid'];
        $newData['OSVERSION'] = $data['osv'];
        $newData['DEVICETYPE'] = $data['device'];
        $newData['date'] = date('Ymd', time());
        $newData['time'] = date('Ym', time());
        $newData['channel'] = $aid;
        
        $actLogic = new \Act\Logic\ActLogic();
        $actLogic->addObserver(new \Act\Logic\Event\TdSelectIdfaFromFddIosCallback());
        $actLogic->addObserver(new \Act\Logic\Event\QianluCallback());
        $actLogic->addObserver(new \Act\Logic\Event\RedisCallback());
        
        Factory::getServer('MqWriteLog')->send('act qianlu insert raw request params:' . json_encode($newData));
        $resultData = false;
        if(count($newData) > 0) {
            $resultData = $actLogic->insert($newData);
        }
        
        return $resultData;
    }
}